import request from 'api/'
import tools from 'tools/'



let plugins = {};
for (var i = 0; i < request.length; i++) {
  if (typeof request[i] === 'object' && request[i].list && Array.isArray(request[i].list)) {
    for (var j = 0; j < request[i].list.length; j++) {
      plugins['api_' + request[i].module + '_' + request[i].list[j].method] = (function (n, m) {
        return function ({type = request[n].list[m].type, path = request[n].list[m].path, data = {}, restfulReq = {}, fn, succFn, errFn, tokenFlag, noLoading, headers, opts} = {}) {
          tools.ajax.call(this, {
            type,
            path,
            data,
            restfulReq,
            fn,
            succFn,
            errFn,
            tokenFlag,
            noLoading,
            headers,
            opts
          });
        };
      })(i, j);
    }
  }
}

export default plugins
